<?php
require_once '../app/Mage.php';
Mage::app('admin');
set_time_limit(0);
ini_set('memory_limit','2048M');
$con = Mage::getSingleton('core/resource')->getConnection('core_write');

/* @var Mage_Eav_Model_Mysql4_Entity_Attribute_Collection */
$collection = Mage::getResourceModel('eav/entity_attribute_collection')
					->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
					->addFieldToFilter('attribute_code',array('like'=>'e_%'))
					->addFieldToFilter('attribute_code',array('neq'=>'enable_googlecheckout'))
					->addFieldToFilter('attribute_code',array('neq'=>'etilize_product_id'))
					->addFieldToFilter('attribute_code',array('neq'=>'e_etilize_pid'))
					;
//->

//m($collection);
foreach($collection as $attrib) {
	//p($attrib->getAttributeCode(),0);
	deleteAttrib($attrib);
	//exit;
}

function deleteAttrib($attrib) {
	if ($attrib->getAttributeId()) {
		$model = Mage::getModel('catalog/resource_eav_attribute');
		// entity type check
		$model->load($id);
		try {
			$model->delete();
			$installer = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('core_setup');
			$installer->removeAttribute(Mage::getModel('catalog/product')->getResource()->getTypeId(),$attrib->getAttributeCode() );
			print "<br>".$attrib->getAttributeCode().' deleted';
		}catch (Exception $e) {
			print "<br>".$attrib->getAttributeCode().' You cannot delete this attribute';
			die($e->getMessage());
		}
	}

}
function p($ar, $exit=1)
{
	print "<pre>";
	print_r($ar);
	print "</pre>";
	if($exit == 1) 	exit;
}
function m($obj, $exit=1)
{
	print "<pre>";
	echo "Class : ". get_class($obj). "<BR/>";
	print_r(get_class_methods(get_class($obj)));
	print "</pre>";
	if($exit == 1) 	exit;
}